import time
import pymongo
from bson.objectid import ObjectId
#将Mongodb中ObjectId转换成unix时间戳
def timestamp_from_objectid(objectid):
     result = 0
     try:
      result = time.mktime(objectid.generation_time.timetuple())
     except:
      pass
     return result

def wenjuanbianhao(): #得到问卷编号
    myclient = pymongo.MongoClient("mongodb://localhost:27017/")
    mydb = myclient["question"]
    mycol = mydb["data1"]

    for x in mycol.find({}, {'_id': 1}):  # 只查询Objectid
        print(timestamp_from_objectid(ObjectId(str(list(x.values())[0]))))  # 从Objectid中获取unix时间戳
    return 0